<?php
/**
 * Created by JetBrains PhpStorm.
 * User: ZhangYi
 * Date: 11-9-26
 * Time: 上午10:29
 * To change this template use File | Settings | File Templates.
 */

class ResetWeeklyHitTask extends sfBaseTask
{
    protected function configure()
    {
        parent::configure();
        $this->addOption('env', null, sfCommandOption::PARAMETER_OPTIONAL, 'Changes the environment this task is run in', 'prod');
        $this->namespace = 'ieasy';
        $this->name = 'reset-weeklyHit';
    }

    /**
     * Executes the current task.
     *
     * @param array    $arguments  An array of arguments
     * @param array    $options    An array of options
     *
     * @return integer 0 if everything went fine, or an error code
     */
    protected function execute($arguments = array(), $options = array())
    {
        try {
            $databaseManager = new sfDatabaseManager($this->configuration);
            $db = new DbBase();
            $sql = "update News set weekly_hit = 0";
            $db->update($sql);
            $date = date(Constants::$DEFAULT_DATETIME_FORMAT);
            echo $date . ": weekly hit reset success! \n";
        } catch (Exception $e) {
            echo "error! " . $e->getTraceAsString()."\n";
        }
    }
}
